package com.bases {
	import com.Interface.IBase;
	import com.skin.SkinManage;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	/**
	 * 单选CheckBox+label
	 * @author pethan
	 *
	 */
	public class TCheckBox extends TUIComponent implements IBase {
		private var format:TextFormat;
		private var lblText:TLable;
		private var checkButton:TCheckButton;

		public function TCheckBox(){
			super();
			lblText = new TLable();
			format = new TextFormat(null, null, 0x000000);
			checkButton = new TCheckButton();
			this.addChilds(checkButton, lblText);
			this.relayout();
			this.addEventListener(MouseEvent.CLICK, onClick);
		}

		private function onClick(event:MouseEvent):void {
			this.selected = !selected;
		}

		override protected function relayout():void {
			this.lblText.setPos(15, -3);
		}

		/**
		 * 设置显示的文本
		 * @param value
		 *
		 */
		public function set label(value:String):void {
			this.lblText.text = value;
			this.lblText.setSize(lblText.textWidth + 20, 20);
		}

		public function setFontSize(size:uint, color:uint = 0x000000):void {
			format = new TextFormat(null, size, color);
			this.lblText.setTextFormat(format);
		}

		/**
		 * 设置选中状态,true为选中,false为不选中
		 * @param value
		 *
		 */
		public function set selected(value:Boolean):void {
			this.checkButton.select = value;
		}

		/**
		 * 是否选中
		 * @return
		 *
		 */
		public function get selected():Boolean {
			return checkButton.select;
		}

		/**
		 *
		 * @param value
		 *
		 */
		public function set textFormat(value:TextFormat):void {
			if (this.lblText != null){
				this.lblText.setTextFormat(value);
			}
		}

		/**
		 * 设置文本的位置
		 * @param x X坐标
		 * @param y Y坐标
		 *
		 */
		public function setLabelPos(x:Number, y:Number):void {
			this.lblText.setPos(x, y);
		}

		/**
		 * 设置是否需要label,如不需要可以直接移除label
		 * @param value true:为不动,flase为移除label
		 *
		 */
		public function set needLabel(value:Boolean):void {
			if (!value){
				this.removeChild(this.lblText);
			}
		}
	}
}